package com.chenwang.measure.ui.adapter;

import android.support.annotation.Nullable;
import android.support.constraint.ConstraintLayout;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenwang.measure.R;
import com.chenwang.measure.model.bean.MainBean;
import com.chenwang.measure.model.bean.Task;

import com.chenwang.measure.utils.DistanceUtils;

import java.util.List;

/**
 * @松 on 2019/7/18 09:50
 *  任务适配器
 */
public class MeasureAdapter extends BaseQuickAdapter <Task.Segment,BaseViewHolder>{
    public MeasureAdapter(@Nullable List<Task.Segment> data) {
        super(R.layout.item_measure, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Task.Segment item) {
        helper.setText( R.id.tv_distance,"");
        ConstraintLayout cl = helper.getView(R.id.cl);
        TextView state = helper.getView(R.id.tv_state);
        helper.setText(R.id.tv_name, item.getStatr().getStationName()+item.getStatr().getSemaphoreName()+"———" +
                item.getEnd().getStationName()+item.getEnd().getSemaphoreName());
        if (item.getState() == 0) {

        if (!TextUtils.isEmpty(item.getStatr().getLonAndlat())){
            if (!TextUtils.isEmpty(item.getEnd().getLonAndlat())){
                item.setState(3);
                item.setDistance(DistanceUtils.decimalTwo(DistanceUtils.getDistance(
                        DistanceUtils.getLon(item.getStatr().getLonAndlat()), DistanceUtils.getLat(item.getStatr().getLonAndlat()),
                        DistanceUtils.getLon(item.getEnd().getLonAndlat()),
                        DistanceUtils.getLat(item.getEnd().getLonAndlat()))));
            }else {
                item.setState(1);
            }
        }
        if (!TextUtils.isEmpty(item.getEnd().getLonAndlat())){
            if (!TextUtils.isEmpty(item.getStatr().getLonAndlat())){
                item.setState(3);
                item.setDistance(DistanceUtils.decimalTwo(DistanceUtils.getDistance(
                        DistanceUtils.getLon(item.getStatr().getLonAndlat()), DistanceUtils.getLat(item.getStatr().getLonAndlat()),
                        DistanceUtils.getLon(item.getEnd().getLonAndlat()),
                        DistanceUtils.getLat(item.getEnd().getLonAndlat()))));
            }else {
                item.setState(2);
            }
        }
        }

      //  0 未   1 开始  2结束  3点都测量过 4完成
        switch (item.getState()){
            case 0:
                state.setText("未完成");
                cl.setBackgroundResource(R.drawable.corners6_s1);
                break;
            case 1:
                state.setText("未完成");
                cl.setBackgroundResource(R.drawable.corners6_s1);
                break;
            case 2:
                state.setText("未完成");
                cl.setBackgroundResource(R.drawable.corners6_s1);
                break;
            case 3:
                state.setText("已完成");
                cl.setBackgroundResource(R.drawable.corners6_s1_red);
                if (!TextUtils.isEmpty(item.getStatr().getSemaphoreSpace())){
                    helper.setText( R.id.tv_distance,item.getStatr().getSemaphoreSpace()+"");
                }else {
                    helper.setText( R.id.tv_distance,"");
                }
                break;
            case 4:
                state.setText("已完成");
                cl.setBackgroundResource(R.drawable.corners6_s1_bule);
                if (!TextUtils.isEmpty(item.getStatr().getSemaphoreSpace())){
                    helper.setText( R.id.tv_distance,item.getStatr().getSemaphoreSpace()+"");
                }else {
                    helper.setText( R.id.tv_distance,"");
                }
                break;
            case 5:
                state.setText("已完成");
                cl.setBackgroundResource(R.drawable.corners6_s1_bule);
                if (!TextUtils.isEmpty(item.getStatr().getSemaphoreSpace())){
                    helper.setText( R.id.tv_distance,item.getStatr().getSemaphoreSpace()+"");
                }else {

                }
                break;
        }



    }
}
